<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://unpkg.com/vue/dist/vue.min.js"></script>
</head>
<body>
    <div id="app">
        <div :class="{'active' :isActive}">最简单的class设置</div>
        <div class="static" :class="{'active':isActive,'error':isError}">多个class的连用</div>
        <div class="static" :class="[classA,classB,classC]">数组多个class的连用</div>
        <div class="static" :class="[isActive ? classA:classB,classC]">三元表达式数组多个class的连用，用数组扩起来</div>
        <div class="static" :class="[{'active':isActive},classA]">对象的使用方法，用数组扩起来</div>
        <div class="static" :class="classes">利用computed属性来设置class,注意这里的写法，直接<span :class="classD">“方法”</span></div>
        <div class="static" :class="classes2">利用computed属性来设置class,注意这里的写法，直接<span :class="classD">“方法”,较复杂，请注意用法，嵌套的【】</span></div>
        
        <my-component :class="{'active':isActive}"></my-component>
        <div :style="{'color':color,'font-size':size+'px'}">style的用法</div>
        <div :style="styles">style在data里的用法</div>
        <div :style="[styles,styles2]">style在data里的用法[数组】</div>
    </div>
    <script>
        Vue.component('my-component',{
            template:'<p class="art">class在组件中的用法</p>'
        })

        var app = new Vue({
            el:'#app',
            data:{
                isActive: true,
                isError:true,
                classA:'btn',
                classB:'default',
                classC:'extends',
                classD: 'red',
                size:'lagrge',
                disabled:true,
                color:'red',
                size: '50',
                styles:{
                    color:'yellow',
                    fontSize:50+'px'
                },
                styles2:{
                    backgroundColor:'red',
                    color:'white'
                }
            },
            computed:{
                classes:function(){
                    return this.classA + ' ' + this.classB + ' ' + this.classC;
                },
                classes2:function(){
                    return [
                        'btn',{
                            ['btn-'+this.size]:this.size !='',
                            ['btn-disabled']:this.disabled
                        }
                    ]
                }

            }
        })
    </script>
    <style>
        .red{color: rgb(126, 128, 0);}
    </style>
    
</body>
</html>